package com.travelmood.controller;

import com.travelmood.pojo.Mood;
import com.travelmood.pojo.Result;
import com.travelmood.service.MoodService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/moods")
public class MoodController {

    @Autowired
    private MoodService moodService;

    @PostMapping("/add")
    public Result addMood(@RequestBody Mood mood) {
        try {
            moodService.addMood(mood);
            return Result.success();
        } catch (Exception e) {
            return Result.error("发生错误，无法添加心情");
        }
    }

    @PutMapping("/update")
    public Result updateMood(@RequestBody Mood mood) {
        try {
            moodService.updateMood(mood);
            return Result.success();
        } catch (Exception e) {
            return Result.error("发生错误，无法更新心情");
        }
    }

    @DeleteMapping("/delete")
    public Result deleteMood(@RequestParam Integer moodId) {
        try {
            moodService.deleteMoodById(moodId);
            return Result.success();
        } catch (Exception e) {
            return Result.error("发生错误，无法删除心情");
        }
    }

    @GetMapping("/get")
    public Result getMood(@RequestParam Integer moodId) {
        try {
            Mood mood = moodService.findMoodById(moodId);
            return Result.success(mood);
        } catch (Exception e) {
            return Result.error("发生错误，无法查询心情");
        }
    }

    @GetMapping("/all")
    public Result getAllMoods() {
        try {
            List<Mood> moods = moodService.getAllMoods();
            return Result.success(moods);
        } catch (Exception e) {
            return Result.error("发生错误，无法获取心情列表");
        }
    }
    @GetMapping("/getplacemood")
    public Result getMoodsByPlaceId(@RequestParam Integer placeId) {
        try {
            List<Mood> moods = moodService.findMoodsByPlaceId(placeId);
            return Result.success(moods);
        } catch (Exception e) {
            return Result.error("发生错误，无法获取地点的心情列表");
        }
    }
}

